package com.foreverwin.jzymes.report.crop.controller;

import com.foreverwin.jzymes.common.service.ISiteAdviceService;
import com.foreverwin.jzymes.common.util.CommonMethods;
import com.foreverwin.jzymes.framework.base.AjaxResult;
import com.foreverwin.jzymes.framework.exception.BusinessException;
import com.foreverwin.jzymes.report.crop.service.ICropMobilityReportService;
import com.foreverwin.jzymes.report.crop.service.IFailureRateReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;

@RestController
@RequestMapping("/report/failure")
public class FailureRateReportController {
    @Autowired
    IFailureRateReportService failureRateReportService;
    @Autowired
    ISiteAdviceService siteAdviceService;


    @RequestMapping("/failureRateReport")
    public AjaxResult failureRateReport(@RequestParam Map<String , Object> jsonMap){
        try{
            String site = CommonMethods.getSite();
            siteAdviceService.existSite( site );
            jsonMap.put("site",site);

            Map< String,Object > list = null;
            try {
                list = failureRateReportService.findFailureRateReport( jsonMap );
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return AjaxResult.returnSuccess().put("value",list);
        }catch ( BusinessException e ){
            return AjaxResult.returnError( e.getMessage() );
        }
    }


}
